

<!DOCTYPE html>
<!--[if IE 8]><html class="no-js lt-ie9" lang="en" > <![endif]-->
<!--[if gt IE 8]><!--> <html class="no-js" lang="en" > <!--<![endif]-->
<head>
  <meta charset="utf-8">
  
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  
  <title>federatedml.statistic.test.statics_test &mdash; FATE 1.0 documentation</title>
  

  
  
  
  

  
  <script type="text/javascript" src="../../../../_static/js/modernizr.min.js"></script>
  
    
      <script type="text/javascript" id="documentation_options" data-url_root="../../../../" src="../../../../_static/documentation_options.js"></script>
        <script type="text/javascript" src="../../../../_static/jquery.js"></script>
        <script type="text/javascript" src="../../../../_static/underscore.js"></script>
        <script type="text/javascript" src="../../../../_static/doctools.js"></script>
        <script type="text/javascript" src="../../../../_static/language_data.js"></script>
    
    <script type="text/javascript" src="../../../../_static/js/theme.js"></script>

    

  
  <link rel="stylesheet" href="../../../../_static/css/theme.css" type="text/css" />
  <link rel="stylesheet" href="../../../../_static/pygments.css" type="text/css" />
    <link rel="index" title="Index" href="../../../../genindex.html" />
    <link rel="search" title="Search" href="../../../../search.html" /> 
</head>

<body class="wy-body-for-nav">

   
  <div class="wy-grid-for-nav">
    
    <nav data-toggle="wy-nav-shift" class="wy-nav-side">
      <div class="wy-side-scroll">
        <div class="wy-side-nav-search" >
          

          
            <a href="../../../../index.html" class="icon icon-home"> FATE
          

          
          </a>

          
            
            
          

          
<div role="search">
  <form id="rtd-search-form" class="wy-form" action="../../../../search.html" method="get">
    <input type="text" name="q" placeholder="Search docs" />
    <input type="hidden" name="check_keywords" value="yes" />
    <input type="hidden" name="area" value="default" />
  </form>
</div>

          
        </div>

        <div class="wy-menu wy-menu-vertical" data-spy="affix" role="navigation" aria-label="main navigation">
          
            
            
              
            
            
              <!-- Local TOC -->
              <div class="local-toc"></div>
            
          
        </div>
      </div>
    </nav>

    <section data-toggle="wy-nav-shift" class="wy-nav-content-wrap">

      
      <nav class="wy-nav-top" aria-label="top navigation">
        
          <i data-toggle="wy-nav-top" class="fa fa-bars"></i>
          <a href="../../../../index.html">FATE</a>
        
      </nav>


      <div class="wy-nav-content">
        
        <div class="rst-content">
        
          















<div role="navigation" aria-label="breadcrumbs navigation">

  <ul class="wy-breadcrumbs">
    
      <li><a href="../../../../index.html">Docs</a> &raquo;</li>
        
          <li><a href="../../../index.html">Module code</a> &raquo;</li>
        
      <li>federatedml.statistic.test.statics_test</li>
    
    
      <li class="wy-breadcrumbs-aside">
        
      </li>
    
  </ul>

  
  <hr/>
</div>
          <div role="main" class="document" itemscope="itemscope" itemtype="http://schema.org/Article">
           <div itemprop="articleBody">
            
  <h1>Source code for federatedml.statistic.test.statics_test</h1><div class="highlight"><pre>
<span></span><span class="kn">import</span> <span class="nn">math</span>
<span class="kn">import</span> <span class="nn">unittest</span>

<span class="kn">import</span> <span class="nn">numpy</span> <span class="k">as</span> <span class="nn">np</span>

<span class="kn">from</span> <span class="nn">arch.api</span> <span class="k">import</span> <span class="n">eggroll</span>
<span class="kn">from</span> <span class="nn">federatedml.util</span> <span class="k">import</span> <span class="n">consts</span>

<span class="n">eggroll</span><span class="o">.</span><span class="n">init</span><span class="p">(</span><span class="s2">&quot;123&quot;</span><span class="p">)</span>

<span class="kn">from</span> <span class="nn">federatedml.statistic.statics</span> <span class="k">import</span> <span class="n">MultivariateStatisticalSummary</span>
<span class="kn">from</span> <span class="nn">federatedml.feature.instance</span> <span class="k">import</span> <span class="n">Instance</span>


<div class="viewcode-block" id="TestStatistics"><a class="viewcode-back" href="../../../../federatedml.statistic.test.html#federatedml.statistic.test.statics_test.TestStatistics">[docs]</a><span class="k">class</span> <span class="nc">TestStatistics</span><span class="p">(</span><span class="n">unittest</span><span class="o">.</span><span class="n">TestCase</span><span class="p">):</span>
<div class="viewcode-block" id="TestStatistics.setUp"><a class="viewcode-back" href="../../../../federatedml.statistic.test.html#federatedml.statistic.test.statics_test.TestStatistics.setUp">[docs]</a>    <span class="k">def</span> <span class="nf">setUp</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
        <span class="n">eggroll</span><span class="o">.</span><span class="n">init</span><span class="p">(</span><span class="s2">&quot;test_instance&quot;</span><span class="p">)</span>
        <span class="n">dense_inst</span> <span class="o">=</span> <span class="p">[]</span>
        <span class="n">dense_not_inst</span> <span class="o">=</span> <span class="p">[]</span>
        <span class="n">headers</span> <span class="o">=</span> <span class="p">[</span><span class="s1">&#39;x&#39;</span> <span class="o">+</span> <span class="nb">str</span><span class="p">(</span><span class="n">i</span><span class="p">)</span> <span class="k">for</span> <span class="n">i</span> <span class="ow">in</span> <span class="nb">range</span><span class="p">(</span><span class="mi">20</span><span class="p">)]</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">header</span> <span class="o">=</span> <span class="n">headers</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">eps</span> <span class="o">=</span> <span class="mf">1e-5</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">count</span> <span class="o">=</span> <span class="mi">100</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">dense_data_transpose</span> <span class="o">=</span> <span class="p">[]</span>
        <span class="k">for</span> <span class="n">i</span> <span class="ow">in</span> <span class="nb">range</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">count</span><span class="p">):</span>
            <span class="n">features</span> <span class="o">=</span> <span class="n">i</span> <span class="o">%</span> <span class="mi">16</span> <span class="o">*</span> <span class="n">np</span><span class="o">.</span><span class="n">ones</span><span class="p">(</span><span class="mi">20</span><span class="p">)</span>
            <span class="n">inst</span> <span class="o">=</span> <span class="n">Instance</span><span class="p">(</span><span class="n">features</span><span class="o">=</span><span class="n">features</span><span class="p">)</span>
            <span class="n">dense_inst</span><span class="o">.</span><span class="n">append</span><span class="p">((</span><span class="n">i</span><span class="p">,</span> <span class="n">inst</span><span class="p">))</span>
            <span class="bp">self</span><span class="o">.</span><span class="n">dense_data_transpose</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="n">features</span><span class="p">)</span>
            <span class="n">dense_not_inst</span><span class="o">.</span><span class="n">append</span><span class="p">((</span><span class="n">i</span><span class="p">,</span> <span class="n">features</span><span class="p">))</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">dense_inst</span> <span class="o">=</span> <span class="n">dense_inst</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">dense_not_inst</span> <span class="o">=</span> <span class="n">dense_not_inst</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">dense_data_transpose</span> <span class="o">=</span> <span class="n">np</span><span class="o">.</span><span class="n">array</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">dense_data_transpose</span><span class="p">)</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">dense_data_transpose</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">dense_data_transpose</span><span class="o">.</span><span class="n">transpose</span><span class="p">()</span>

        <span class="bp">self</span><span class="o">.</span><span class="n">dense_table</span> <span class="o">=</span> <span class="n">eggroll</span><span class="o">.</span><span class="n">parallelize</span><span class="p">(</span><span class="n">dense_inst</span><span class="p">,</span> <span class="n">include_key</span><span class="o">=</span><span class="kc">True</span><span class="p">,</span> <span class="n">partition</span><span class="o">=</span><span class="mi">5</span><span class="p">)</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">dense_not_inst_table</span> <span class="o">=</span> <span class="n">eggroll</span><span class="o">.</span><span class="n">parallelize</span><span class="p">(</span><span class="n">dense_not_inst</span><span class="p">,</span> <span class="n">include_key</span><span class="o">=</span><span class="kc">True</span><span class="p">,</span> <span class="n">partition</span><span class="o">=</span><span class="mi">5</span><span class="p">)</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">dense_table</span><span class="o">.</span><span class="n">schema</span> <span class="o">=</span> <span class="p">{</span><span class="s1">&#39;header&#39;</span><span class="p">:</span> <span class="n">headers</span><span class="p">}</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">dense_not_inst_table</span><span class="o">.</span><span class="n">schema</span> <span class="o">=</span> <span class="p">{</span><span class="s1">&#39;header&#39;</span><span class="p">:</span> <span class="n">headers</span><span class="p">}</span>

        <span class="n">col_index</span> <span class="o">=</span> <span class="p">[</span><span class="mi">1</span><span class="p">,</span> <span class="mi">2</span><span class="p">,</span> <span class="mi">3</span><span class="p">]</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">col_index</span> <span class="o">=</span> <span class="n">col_index</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">summary_obj</span> <span class="o">=</span> <span class="n">MultivariateStatisticalSummary</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">dense_table</span><span class="p">,</span> <span class="n">col_index</span><span class="p">,</span> <span class="n">abnormal_list</span><span class="o">=</span><span class="p">[</span><span class="kc">None</span><span class="p">])</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">summary_obj_not_inst</span> <span class="o">=</span> <span class="n">MultivariateStatisticalSummary</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">dense_not_inst_table</span><span class="p">,</span> <span class="n">col_index</span><span class="p">,</span>
                                                                   <span class="n">abnormal_list</span><span class="o">=</span><span class="p">[</span><span class="kc">None</span><span class="p">])</span></div>

<div class="viewcode-block" id="TestStatistics.test_MultivariateStatisticalSummary"><a class="viewcode-back" href="../../../../federatedml.statistic.test.html#federatedml.statistic.test.statics_test.TestStatistics.test_MultivariateStatisticalSummary">[docs]</a>    <span class="k">def</span> <span class="nf">test_MultivariateStatisticalSummary</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>

        <span class="k">for</span> <span class="n">col</span> <span class="ow">in</span> <span class="bp">self</span><span class="o">.</span><span class="n">col_index</span><span class="p">:</span>
            <span class="n">col_name</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">header</span><span class="p">[</span><span class="n">col</span><span class="p">]</span>
            <span class="n">this_data</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">dense_data_transpose</span><span class="p">[</span><span class="n">col</span><span class="p">]</span>
            <span class="n">mean</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">summary_obj</span><span class="o">.</span><span class="n">get_mean</span><span class="p">()[</span><span class="n">col_name</span><span class="p">]</span>
            <span class="n">var</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">summary_obj</span><span class="o">.</span><span class="n">get_variance</span><span class="p">()[</span><span class="n">col_name</span><span class="p">]</span>
            <span class="n">max_value</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">summary_obj</span><span class="o">.</span><span class="n">get_max</span><span class="p">()[</span><span class="n">col_name</span><span class="p">]</span>
            <span class="n">min_value</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">summary_obj</span><span class="o">.</span><span class="n">get_min</span><span class="p">()[</span><span class="n">col_name</span><span class="p">]</span>

            <span class="n">real_max</span> <span class="o">=</span> <span class="n">np</span><span class="o">.</span><span class="n">max</span><span class="p">(</span><span class="n">this_data</span><span class="p">)</span>
            <span class="n">real_min</span> <span class="o">=</span> <span class="n">np</span><span class="o">.</span><span class="n">min</span><span class="p">(</span><span class="n">this_data</span><span class="p">)</span>
            <span class="n">real_mean</span> <span class="o">=</span> <span class="n">np</span><span class="o">.</span><span class="n">mean</span><span class="p">(</span><span class="n">this_data</span><span class="p">)</span>
            <span class="n">real_var</span> <span class="o">=</span> <span class="n">np</span><span class="o">.</span><span class="n">var</span><span class="p">(</span><span class="n">this_data</span><span class="p">)</span>
            <span class="bp">self</span><span class="o">.</span><span class="n">assertTrue</span><span class="p">(</span><span class="n">math</span><span class="o">.</span><span class="n">fabs</span><span class="p">(</span><span class="n">mean</span> <span class="o">-</span> <span class="n">real_mean</span><span class="p">)</span> <span class="o">&lt;</span> <span class="bp">self</span><span class="o">.</span><span class="n">eps</span><span class="p">)</span>
            <span class="bp">self</span><span class="o">.</span><span class="n">assertTrue</span><span class="p">(</span><span class="n">math</span><span class="o">.</span><span class="n">fabs</span><span class="p">(</span><span class="n">var</span> <span class="o">-</span> <span class="n">real_var</span><span class="p">)</span> <span class="o">&lt;</span> <span class="bp">self</span><span class="o">.</span><span class="n">eps</span><span class="p">)</span>
            <span class="bp">self</span><span class="o">.</span><span class="n">assertTrue</span><span class="p">(</span><span class="n">max_value</span> <span class="o">==</span> <span class="n">real_max</span><span class="p">)</span>
            <span class="bp">self</span><span class="o">.</span><span class="n">assertTrue</span><span class="p">(</span><span class="n">min_value</span> <span class="o">==</span> <span class="n">real_min</span><span class="p">)</span></div>

<div class="viewcode-block" id="TestStatistics.test_median"><a class="viewcode-back" href="../../../../federatedml.statistic.test.html#federatedml.statistic.test.statics_test.TestStatistics.test_median">[docs]</a>    <span class="k">def</span> <span class="nf">test_median</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
        <span class="n">error</span> <span class="o">=</span> <span class="n">consts</span><span class="o">.</span><span class="n">DEFAULT_RELATIVE_ERROR</span>
        <span class="n">medians</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">summary_obj</span><span class="o">.</span><span class="n">get_median</span><span class="p">()</span>

        <span class="k">for</span> <span class="n">col_idx</span> <span class="ow">in</span> <span class="bp">self</span><span class="o">.</span><span class="n">col_index</span><span class="p">:</span>
            <span class="n">col_name</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">header</span><span class="p">[</span><span class="n">col_idx</span><span class="p">]</span>
            <span class="c1"># for _, an_instance in self.dense_inst:</span>
            <span class="c1">#     features = an_instance.features</span>
            <span class="c1">#     all_data.append(features[col_idx])</span>
            <span class="n">all_data</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">dense_data_transpose</span><span class="p">[</span><span class="n">col_idx</span><span class="p">]</span>
            <span class="n">sort_data</span> <span class="o">=</span> <span class="nb">sorted</span><span class="p">(</span><span class="n">all_data</span><span class="p">)</span>
            <span class="n">min_rank</span> <span class="o">=</span> <span class="nb">int</span><span class="p">(</span><span class="n">math</span><span class="o">.</span><span class="n">floor</span><span class="p">((</span><span class="mf">0.5</span> <span class="o">-</span> <span class="mi">2</span> <span class="o">*</span> <span class="n">error</span><span class="p">)</span> <span class="o">*</span> <span class="bp">self</span><span class="o">.</span><span class="n">count</span><span class="p">))</span>
            <span class="n">max_rank</span> <span class="o">=</span> <span class="nb">int</span><span class="p">(</span><span class="n">math</span><span class="o">.</span><span class="n">ceil</span><span class="p">((</span><span class="mf">0.5</span> <span class="o">+</span> <span class="mi">2</span> <span class="o">*</span> <span class="n">error</span><span class="p">)</span> <span class="o">*</span> <span class="bp">self</span><span class="o">.</span><span class="n">count</span><span class="p">))</span>
            <span class="bp">self</span><span class="o">.</span><span class="n">assertTrue</span><span class="p">(</span><span class="n">sort_data</span><span class="p">[</span><span class="n">min_rank</span><span class="p">]</span> <span class="o">&lt;=</span> <span class="n">medians</span><span class="p">[</span><span class="n">col_name</span><span class="p">]</span> <span class="o">&lt;=</span> <span class="n">sort_data</span><span class="p">[</span><span class="n">max_rank</span><span class="p">])</span></div>

<div class="viewcode-block" id="TestStatistics.test_MultivariateStatisticalSummary_not_inst_version"><a class="viewcode-back" href="../../../../federatedml.statistic.test.html#federatedml.statistic.test.statics_test.TestStatistics.test_MultivariateStatisticalSummary_not_inst_version">[docs]</a>    <span class="k">def</span> <span class="nf">test_MultivariateStatisticalSummary_not_inst_version</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>

        <span class="k">for</span> <span class="n">col</span> <span class="ow">in</span> <span class="bp">self</span><span class="o">.</span><span class="n">col_index</span><span class="p">:</span>
            <span class="n">col_name</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">header</span><span class="p">[</span><span class="n">col</span><span class="p">]</span>
            <span class="n">this_data</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">dense_data_transpose</span><span class="p">[</span><span class="n">col</span><span class="p">]</span>
            <span class="n">mean</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">summary_obj_not_inst</span><span class="o">.</span><span class="n">get_mean</span><span class="p">()[</span><span class="n">col_name</span><span class="p">]</span>
            <span class="n">var</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">summary_obj_not_inst</span><span class="o">.</span><span class="n">get_variance</span><span class="p">()[</span><span class="n">col_name</span><span class="p">]</span>
            <span class="n">max_value</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">summary_obj_not_inst</span><span class="o">.</span><span class="n">get_max</span><span class="p">()[</span><span class="n">col_name</span><span class="p">]</span>
            <span class="n">min_value</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">summary_obj_not_inst</span><span class="o">.</span><span class="n">get_min</span><span class="p">()[</span><span class="n">col_name</span><span class="p">]</span>

            <span class="n">real_max</span> <span class="o">=</span> <span class="n">np</span><span class="o">.</span><span class="n">max</span><span class="p">(</span><span class="n">this_data</span><span class="p">)</span>
            <span class="n">real_min</span> <span class="o">=</span> <span class="n">np</span><span class="o">.</span><span class="n">min</span><span class="p">(</span><span class="n">this_data</span><span class="p">)</span>
            <span class="n">real_mean</span> <span class="o">=</span> <span class="n">np</span><span class="o">.</span><span class="n">mean</span><span class="p">(</span><span class="n">this_data</span><span class="p">)</span>
            <span class="n">real_var</span> <span class="o">=</span> <span class="n">np</span><span class="o">.</span><span class="n">var</span><span class="p">(</span><span class="n">this_data</span><span class="p">)</span>

            <span class="bp">self</span><span class="o">.</span><span class="n">assertTrue</span><span class="p">(</span><span class="n">math</span><span class="o">.</span><span class="n">fabs</span><span class="p">(</span><span class="n">mean</span> <span class="o">-</span> <span class="n">real_mean</span><span class="p">)</span> <span class="o">&lt;</span> <span class="bp">self</span><span class="o">.</span><span class="n">eps</span><span class="p">)</span>
            <span class="bp">self</span><span class="o">.</span><span class="n">assertTrue</span><span class="p">(</span><span class="n">math</span><span class="o">.</span><span class="n">fabs</span><span class="p">(</span><span class="n">var</span> <span class="o">-</span> <span class="n">real_var</span><span class="p">)</span> <span class="o">&lt;</span> <span class="bp">self</span><span class="o">.</span><span class="n">eps</span><span class="p">)</span>
            <span class="bp">self</span><span class="o">.</span><span class="n">assertTrue</span><span class="p">(</span><span class="n">max_value</span> <span class="o">==</span> <span class="n">real_max</span><span class="p">)</span>
            <span class="bp">self</span><span class="o">.</span><span class="n">assertTrue</span><span class="p">(</span><span class="n">min_value</span> <span class="o">==</span> <span class="n">real_min</span><span class="p">)</span></div>

<div class="viewcode-block" id="TestStatistics.test_median_not_inst"><a class="viewcode-back" href="../../../../federatedml.statistic.test.html#federatedml.statistic.test.statics_test.TestStatistics.test_median_not_inst">[docs]</a>    <span class="k">def</span> <span class="nf">test_median_not_inst</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
        <span class="n">error</span> <span class="o">=</span> <span class="n">consts</span><span class="o">.</span><span class="n">DEFAULT_RELATIVE_ERROR</span>
        <span class="n">medians</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">summary_obj_not_inst</span><span class="o">.</span><span class="n">get_median</span><span class="p">()</span>

        <span class="k">for</span> <span class="n">col_idx</span> <span class="ow">in</span> <span class="bp">self</span><span class="o">.</span><span class="n">col_index</span><span class="p">:</span>
            <span class="n">col_name</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">header</span><span class="p">[</span><span class="n">col_idx</span><span class="p">]</span>
            <span class="k">if</span> <span class="n">col_idx</span> <span class="ow">not</span> <span class="ow">in</span> <span class="bp">self</span><span class="o">.</span><span class="n">col_index</span><span class="p">:</span>
                <span class="k">continue</span>
            <span class="n">all_data</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">dense_data_transpose</span><span class="p">[</span><span class="n">col_idx</span><span class="p">]</span>
            <span class="n">sort_data</span> <span class="o">=</span> <span class="nb">sorted</span><span class="p">(</span><span class="n">all_data</span><span class="p">)</span>
            <span class="n">min_rank</span> <span class="o">=</span> <span class="nb">int</span><span class="p">(</span><span class="n">math</span><span class="o">.</span><span class="n">floor</span><span class="p">((</span><span class="mf">0.5</span> <span class="o">-</span> <span class="mi">2</span> <span class="o">*</span> <span class="n">error</span><span class="p">)</span> <span class="o">*</span> <span class="bp">self</span><span class="o">.</span><span class="n">count</span><span class="p">))</span>
            <span class="n">max_rank</span> <span class="o">=</span> <span class="nb">int</span><span class="p">(</span><span class="n">math</span><span class="o">.</span><span class="n">ceil</span><span class="p">((</span><span class="mf">0.5</span> <span class="o">+</span> <span class="mi">2</span> <span class="o">*</span> <span class="n">error</span><span class="p">)</span> <span class="o">*</span> <span class="bp">self</span><span class="o">.</span><span class="n">count</span><span class="p">))</span>
            <span class="bp">self</span><span class="o">.</span><span class="n">assertTrue</span><span class="p">(</span><span class="n">sort_data</span><span class="p">[</span><span class="n">min_rank</span><span class="p">]</span> <span class="o">&lt;=</span> <span class="n">medians</span><span class="p">[</span><span class="n">col_name</span><span class="p">]</span> <span class="o">&lt;=</span> <span class="n">sort_data</span><span class="p">[</span><span class="n">max_rank</span><span class="p">])</span></div>

<div class="viewcode-block" id="TestStatistics.test_quantile_query"><a class="viewcode-back" href="../../../../federatedml.statistic.test.html#federatedml.statistic.test.statics_test.TestStatistics.test_quantile_query">[docs]</a>    <span class="k">def</span> <span class="nf">test_quantile_query</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
        <span class="n">quantile_points</span> <span class="o">=</span> <span class="p">[</span><span class="mf">0.25</span><span class="p">,</span> <span class="mf">0.5</span><span class="p">,</span> <span class="mf">0.75</span><span class="p">,</span> <span class="mf">1.0</span><span class="p">]</span>
        <span class="n">expect_value</span> <span class="o">=</span> <span class="p">[</span><span class="mi">3</span><span class="p">,</span> <span class="mi">7</span><span class="p">,</span> <span class="mi">11</span><span class="p">,</span> <span class="mi">15</span><span class="p">]</span>
        <span class="k">for</span> <span class="n">idx</span><span class="p">,</span> <span class="n">quantile</span> <span class="ow">in</span> <span class="nb">enumerate</span><span class="p">(</span><span class="n">quantile_points</span><span class="p">):</span>
            <span class="n">quantile_value</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">summary_obj</span><span class="o">.</span><span class="n">get_quantile_point</span><span class="p">(</span><span class="n">quantile</span><span class="p">)</span>
            <span class="k">for</span> <span class="n">q_value</span> <span class="ow">in</span> <span class="n">quantile_value</span><span class="o">.</span><span class="n">values</span><span class="p">():</span>
                <span class="bp">self</span><span class="o">.</span><span class="n">assertTrue</span><span class="p">(</span><span class="n">q_value</span> <span class="o">==</span> <span class="n">expect_value</span><span class="p">[</span><span class="n">idx</span><span class="p">])</span>

        <span class="k">for</span> <span class="n">idx</span><span class="p">,</span> <span class="n">quantile</span> <span class="ow">in</span> <span class="nb">enumerate</span><span class="p">(</span><span class="n">quantile_points</span><span class="p">):</span>
            <span class="n">quantile_value</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">summary_obj_not_inst</span><span class="o">.</span><span class="n">get_quantile_point</span><span class="p">(</span><span class="n">quantile</span><span class="p">)</span>
            <span class="k">for</span> <span class="n">q_value</span> <span class="ow">in</span> <span class="n">quantile_value</span><span class="o">.</span><span class="n">values</span><span class="p">():</span>
                <span class="bp">self</span><span class="o">.</span><span class="n">assertTrue</span><span class="p">(</span><span class="n">q_value</span> <span class="o">==</span> <span class="n">expect_value</span><span class="p">[</span><span class="n">idx</span><span class="p">])</span></div>

<div class="viewcode-block" id="TestStatistics.tearDown"><a class="viewcode-back" href="../../../../federatedml.statistic.test.html#federatedml.statistic.test.statics_test.TestStatistics.tearDown">[docs]</a>    <span class="k">def</span> <span class="nf">tearDown</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">dense_table</span><span class="o">.</span><span class="n">destroy</span><span class="p">()</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">dense_not_inst_table</span><span class="o">.</span><span class="n">destroy</span><span class="p">()</span></div></div>


<span class="k">if</span> <span class="vm">__name__</span> <span class="o">==</span> <span class="s1">&#39;__main__&#39;</span><span class="p">:</span>
    <span class="n">unittest</span><span class="o">.</span><span class="n">main</span><span class="p">()</span>
</pre></div>

           </div>
           
          </div>
          <footer>
  

  <hr/>

  <div role="contentinfo">
    <p>
        &copy; Copyright 2019, FATE_TEAM

    </p>
  </div>
  Built with <a href="http://sphinx-doc.org/">Sphinx</a> using a <a href="https://github.com/rtfd/sphinx_rtd_theme">theme</a> provided by <a href="https://readthedocs.org">Read the Docs</a>. 

</footer>

        </div>
      </div>

    </section>

  </div>
  


  <script type="text/javascript">
      jQuery(function () {
          SphinxRtdTheme.Navigation.enable(true);
      });
  </script>

  
  
    
   

</body>
</html>